// ------------------------------------------------------------
// @Author: ZhangPeng
// @Date: 2024年12月23日22:53
// ------------------------------------------------------------

using UnityEngine;

/// <summary>
/// 衰减贴图生成器
/// </summary>
public static class FalloffGenerator
{
    
    public static float[,] GenerateFalloffTexture(int size)
    {
        float[,] map = new float[size,size];
        
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                float x = i / (float)size * 2 - 1;
                float y = j / (float)size * 2 - 1;

                float value = Mathf.Max(Mathf.Abs(x), Mathf.Abs(y));
                map[i,j] =Evaluate(value) ;
            }
        }
        return map;
    }

    /// <summary>
    /// 修改曲线，使之贴图中间区域趋于0
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    static float Evaluate(float value)
    {
        float a = 3;
        float b = 2.2f;
        
        return Mathf.Pow(value, a) / (Mathf.Pow(value, a) + Mathf.Pow(b - b* value, a));
    }
}
